// exampleService.ts
import type { AxiosResponse } from 'axios';
import type { WordResponse } from '../types/WordResponse';
import apiClient from '../utils/http';

// 示例 GET 请求
export async function fetchData<T>(url: string): Promise<AxiosResponse< T>> {
  try {
    const response = await apiClient.get<T>(url);
    return response;
  } catch (error) {
    console.error('Fetch error:', error);
    throw error;
  }
}
export async function translate(word:string):Promise<AxiosResponse< WordResponse>> {
    let res = await apiClient.get("/definition?word="+word)
    console.log("res:",res)
    return res
}
// 示例 POST 请求
export async function postData<T>(url: string, data: any): Promise<AxiosResponse<T>> {
  try {
    const response = await apiClient.post<T>(url, data);
    return response;
  } catch (error) {
    console.error('Post error:', error);
    throw error;
  }
}